package cn.szzsi._webpc;

import cn.szzsi._web.BaseWebController;
import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.kit.CommonUtil;
import cn.szzsi.common.model.Area;
import cn.szzsi.common.model.Member;
import cn.szzsi.common.model.MemberAttribute;
import cn.szzsi.common.model.MemberAttribute.AttributeType;
import cn.szzsi.validator.ProfileValidator;
import com.jfinal.aop.Before;
import com.jfinal.kit.StrKit;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 前台类 - 个人信息
 * 
 */
public class ProfileController extends BaseWebPcController<Member> {

	private Member member;
	private String path;//模板路径
	private String shopId;//用户的shopId就是商户的id

	// 编辑
	public void edit() {
		shopId=getLoginMember().getStr("shopId");//用户的shopId对应商户的id(uid),商户的shopId为0
		setAttr("member", getLoginMember());
		setAttr("enabledMemberAttributeList", MemberAttribute.dao.getEnabledMemberAttributeList());
		pcTemplatePath("profile_input.html");
	}

	//TODO
	//获取用户的推荐关系和数据
	public void recommend(){
		shopId=getPara("shopId");
		//第1、2、3级
		path= CommonUtil.getPathByUidAndType(getUid(),CommonUtil.isMobileDevice(getRequest()));//获取模板路径
		setAttr("path",path);
		String type = getPara("type");
		setAttr("type",type);
		if(type.equals("1")){
			setAttr("list", Member.dao.getFirstRecommendByMember(getLoginMember()));
		}else if(type.equals("2")){
			setAttr("list", Member.dao.getFirstRecommendByMember(getLoginMember(),2));
		}else if(type.equals("3")){
			setAttr("list", Member.dao.getFirstRecommendByMember(getLoginMember(),3));
		}
		getTemplatePath(shopId,"recommend");
	}
	//获取当前用户的总推荐数

	public void allRecommend(){
		renderJson(new Msg(true,0, String.valueOf(Member.dao.getRecommendNum(getLoginMember()))));
	}
	
	// 更新
	public void update() {
		member = getModel(Member.class);
		System.out.println(member.getId());
		updated(member);
		redirect("/b/profile/edit");
	}
}
